package com.api.tag.gettagsforuser;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import com.api.test.AbstractApiTest;
import com.zyncro.api.ITagApiService;
import com.zyncro.api.exceptions.ZyncroApiException;
import com.zyncro.api.model.PagedItemsResultApi;
import com.zyncro.api.model.TagApi;
import com.zyncro.api.model.TagApiType;

@ContextConfiguration(locations = { "classpath:/tags/tags-context.xml" })
public class GetTagsForUser extends AbstractApiTest {

	@Value("#{statictags['user.getTags'].appId}")
	private String getTagsUserUrn;

	@Value("#{statictags['user.getTags'].password}")
	private String getTagsUserPassword;

	@Value("#{statictags['cant.tags.forUser.all']}")
	private int cantAllTagsForUser;

	@Value("#{statictags['cant.tags.forUser.category']}")
	private int cantCategoryTagsForUser;

	@Value("#{statictags['cant.tags.forUser.location']}")
	private int cantLocationTagsForUser;

	@BeforeClass
	protected void setParameters() throws Exception {

		getApi().login(getTagsUserUrn, getTagsUserPassword);
	}

	@Test
	public void testGetAllTagsForUser() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		PagedItemsResultApi<TagApi> result = getApi().getService(ITagApiService.class).getTagsForUser(null, pageNumber, itemsPerPage);

		Assert.assertEquals(result.getTotalItems(), cantAllTagsForUser, "Total category-location items");
	}

	@Test
	public void testGetCategoryTagsForUser() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		PagedItemsResultApi<TagApi> result = getApi().getService(ITagApiService.class).getTagsForUser(TagApiType.CATEGORY, pageNumber,
				itemsPerPage);

		Assert.assertEquals(result.getTotalItems(), cantCategoryTagsForUser, "Total category-location items");
	}

	@Test
	public void testGetLocationTagsForUser() throws ZyncroApiException {

		int pageNumber = 0;
		int itemsPerPage = 0;

		PagedItemsResultApi<TagApi> result = getApi().getService(ITagApiService.class).getTagsForUser(TagApiType.LOCATION, pageNumber,
				itemsPerPage);

		Assert.assertEquals(result.getTotalItems(), cantLocationTagsForUser, "Total category-location items");
	}
}
